package com.example.SBootDemo.controller.system;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.SBootDemo.Util.funplace;
import com.example.SBootDemo.model.function.function;
import com.example.SBootDemo.service.Interface.function.deviceInterface;

import net.sf.jsqlparser.expression.Function;

@Controller
public class DeviceReport {
	
	@Autowired
	deviceInterface deviceserver;
	
	
	 @RequestMapping(value="/", method=RequestMethod.GET)
	public String Login(HttpServletRequest request){
		
	        return "index";  
	}
	 
	 
	 @RequestMapping(value="/device/device", method=RequestMethod.GET)
	public String device(HttpServletRequest request){
		
		 	request.setAttribute("List", deviceserver.getDeviceInfo("", "1", "1"));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备定位数据","设备定位列表"));
	        return "device/deviceModel";  
	}
	 
	 //条件查询设备
	 @RequestMapping(value="/device/getdevices", method=RequestMethod.POST)
	public String selectdevice(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="zxc") String deviceID,@RequestParam(value="startTime", defaultValue="1") String startTime,@RequestParam(value="endTime", defaultValue="1") String endTime){
		 	System.out.println(endTime+"----"+startTime);
		 	request.setAttribute("List", deviceserver.getDeviceInfo(deviceID, startTime,endTime));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备定位数据","设备定位列表"));
		 	if(!deviceID.equals("zxc")) {
		 		request.setAttribute("deviceID",deviceID);
		 	}
	        return "device/deviceModel";  
	}
	 //获取定位数据原始MQTT
	 @RequestMapping(value="/device/mqttData", method=RequestMethod.GET)
	 @ResponseBody
	public String mqttData(HttpServletRequest request,Long id,int tip){
		
		 	
	        return  JSONObject.toJSONString(deviceserver.getMqttDataByUpdate(id,tip));
	}
	 
	 
	 
	 //跳转心跳页面
	 @RequestMapping(value="/device/heartbeat", method=RequestMethod.GET)
		public String deviceHeartBeat(HttpServletRequest request){
			
		 	request.setAttribute("List", deviceserver.getDeviceHeartInfo("zxc", "1", "1"));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备心跳数据","心跳列表"));
	        return "device/deviceheartModel";  
	}
	 //心跳条件查询
	 @RequestMapping(value="/device/getdevicesheartbeat", method=RequestMethod.POST)
	public String deviceHeartBeat(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="zxc") String deviceID,@RequestParam(value="startTime", defaultValue="1") String startTime,@RequestParam(value="endTime", defaultValue="1") String endTime){
		 	System.out.println(endTime+"----"+startTime);
		 	request.setAttribute("List", deviceserver.getDeviceHeartInfo(deviceID, startTime,endTime));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备心跳数据","心跳列表"));
		 	if(!deviceID.equals("zxc")) {
		 		request.setAttribute("deviceID",deviceID);
		 	}
	        return "device/deviceheartModel";
	}
	 
	 //跳转命令页面
	 @RequestMapping(value="/device/cmd", method=RequestMethod.GET)
		public String deviceCmd(HttpServletRequest request){
			
		 	request.setAttribute("List", deviceserver.getDeviceCmd("", "1", "1"));
		 	request.setAttribute("List2", deviceserver.getDeviceCmdHistory("", "1", "1"));
		 	request.setAttribute("funplace",new funplace("设备信息查询","命令下发记录","命令列表"));
	        return "device/devicecmdModel";  
	}
	 //命令条件查询
	 @RequestMapping(value="/device/getcmd", method=RequestMethod.POST)
	public String deviceCmd(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="zxc") String deviceID,@RequestParam(value="startTime", defaultValue="1") String startTime,@RequestParam(value="endTime", defaultValue="1") String endTime){
		 	System.out.println(endTime+"----"+startTime);
		 	request.setAttribute("List", deviceserver.getDeviceCmd(deviceID, startTime,endTime));
		 	request.setAttribute("List2", deviceserver.getDeviceCmdHistory(deviceID, startTime,endTime));
		 	request.setAttribute("funplace",new funplace("设备信息查询","命令下发记录","命令列表"));
		 	if(!deviceID.equals("zxc")) {
		 		request.setAttribute("deviceID",deviceID);
		 	}
	        return "device/devicecmdModel";
	}
	 
	 
	 //跳转镣铐上报告警查询页面
	 @RequestMapping(value="/device/alarm", method=RequestMethod.GET)
		public String deviceAlarm(HttpServletRequest request){
			
		 	
		 	request.setAttribute("List", deviceserver.getDeviceAlarm("", "1", "1",""));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备告警记录","设备告警"));
	        return "device/devicealarmModel";  
	}
	 //镣铐上报告警查询
	 @RequestMapping(value="/device/getalarm", method=RequestMethod.POST)
	public String deviceAlarm(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="zxc") String deviceID,@RequestParam(value="startTime", defaultValue="1") String startTime,@RequestParam(value="endTime", defaultValue="1") String endTime,
			@RequestParam(value="alarmType", defaultValue="") String alarmType){
		 	System.out.println(endTime+"----"+startTime);
		 	request.setAttribute("List", deviceserver.getDeviceAlarm(deviceID, startTime,endTime,alarmType));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备告警记录","设备告警"));
		 	if(!deviceID.equals("zxc")) {
		 		request.setAttribute("deviceID",deviceID);
		 	}
	        return "device/devicealarmModel";
	}
	 
	 
	 
	 //跳转镣铐日志查询页面
	 @RequestMapping(value="/device/mqttdata", method=RequestMethod.GET)
		public String deviceMqttdata(HttpServletRequest request){

		 	request.setAttribute("List", deviceserver.getDeviceMq("", "1", "1",""));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备日志查询","设备日志"));
		 	
	        return "device/devicemqttModel";  
	}
	 
	 //镣铐日志查询页面
	 @RequestMapping(value="/device/getmqttdata", method=RequestMethod.POST)
	public String deviceMqttdata(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="zxc") String deviceID,@RequestParam(value="startTime", defaultValue="1") String startTime,@RequestParam(value="endTime", defaultValue="1") String endTime,
			@RequestParam(value="mqType", defaultValue="") String mqType){
		 	request.setAttribute("List", deviceserver.getDeviceMq(deviceID, startTime,endTime,mqType));
		 	request.setAttribute("funplace",new funplace("设备信息查询","设备日志查询","设备日志"));
		 	if(!deviceID.equals("zxc")) {
		 		request.setAttribute("deviceID",deviceID);
		 	}
		 	
	        return "device/devicemqttModel";
	}
	 
	 
	 //跳转监控对象绑定设备查询页面
	 @RequestMapping(value="/device/objecttodevice", method=RequestMethod.GET)
		public String ObjecttoDevice(HttpServletRequest request){

		 	request.setAttribute("List", deviceserver.getObjecttoDevice("",""));
		 	request.setAttribute("funplace",new funplace("关联查询","监控对象绑定的设备","绑定列表"));
		 	//return JSON.toJSONString(deviceserver.getObjecttoDevice("","")); // List转json
		 	 
	        return "device/objecttodeviceModel";
	}
	 
	 //监控对象绑定设备查询页面
	 @RequestMapping(value="/device/getobjecttodevice", method=RequestMethod.POST)
	public String ObjecttoDevice(HttpServletRequest request,@RequestParam(value="firstname", defaultValue="") String firstname,@RequestParam(value="secondname", defaultValue="") String secondname){
		 	request.setAttribute("List", deviceserver.getObjecttoDevice(firstname,secondname));
		 	request.setAttribute("funplace",new funplace("关联查询","监控对象绑定的设备","绑定列表"));
	        return "device/objecttodeviceModel";
	}
	 
	 
	 //跳转设备绑定监控对象查询页面
	 @RequestMapping(value="/device/devicetoobject", method=RequestMethod.GET)
		public String DevicetoObject(HttpServletRequest request){

		 	request.setAttribute("List", deviceserver.getDevicetoObject(""));
		 	request.setAttribute("funplace",new funplace("关联查询","基站设备绑定的监控对象","绑定列表"));
	        return "device/devicetoobjectModel";  
	}
	 
	 //设备绑定监控对象查询页面
	 @RequestMapping(value="/device/getdevicetoobject", method=RequestMethod.POST)
	public String DevicetoObject(HttpServletRequest request,@RequestParam(value="deviceID", defaultValue="") String deviceID){
		 	request.setAttribute("List", deviceserver.getDevicetoObject(deviceID));
		 	request.setAttribute("funplace",new funplace("关联查询","基站设备绑定的监控对象","绑定列表"));
	        return "device/devicetoobjectModel";
	} 
	 
	 
	 
	 //跳转设备绑定监控对象查询页面
	 @RequestMapping(value="/device/MQTT", method=RequestMethod.GET)
		public String MQTT(HttpServletRequest request){
		 request.setAttribute("funplace",new funplace("实时消息查询","MQTT订阅","订阅消息展示"));
		
	        return "device/MQTT";  
	}
	 
	 
	 
	 
	 
}
